/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Newgame;

import Global.ConnectDB;
import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.DefaultComboBoxModel;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Administrator
 */
public class YourScore extends javax.swing.JFrame {
    ConnectDB connectDB;
    CallableStatement cst, cst2;
    ResultSet rs, rs2;
    int flag = 0;
    int ct = 1;
    DefaultTableModel model;
    DefaultComboBoxModel modelcbb;
    /**
     * Creates new form YourScore
     */
    
    
    public YourScore() {
        initComponents();
        SetName();
        cst = null;
        rs = null;
        connectDB = new ConnectDB("1433","localhost","mssqlserver","eproject1","sa","123123");
        connectDB.openConnection();
    }
    
    public int GetScore(String name){
        CallableStatement cst2;
        String sql = "{call GetAllPlayer(?, ?)}";
        try{
            cst2 = connectDB.cn.prepareCall(sql); 
            cst2.setString(1, name);
            cst2.registerOutParameter(2, java.sql.Types.INTEGER);
            cst2.execute();
            return cst2.getInt(2);   
        }catch(SQLException ex){
            ex.printStackTrace();
        }
        return 0;
    }

    public void SetName(){
         Name.setText(Entername.txfname.getText());
         Jscore.setText(String.valueOf(GetScore(Entername.txfname.getText().toString())));
        }
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        Name = new javax.swing.JLabel();
        JScore = new javax.swing.JLabel();
        Jscore = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setMinimumSize(new java.awt.Dimension(369, 225));
        setPreferredSize(new java.awt.Dimension(369, 225));
        setResizable(false);
        getContentPane().setLayout(null);

        jLabel2.setText("have play Puzzle ID:");
        getContentPane().add(jLabel2);
        jLabel2.setBounds(120, 100, 100, 14);

        jLabel3.setText("Name :");
        getContentPane().add(jLabel3);
        jLabel3.setBounds(20, 130, 40, 14);

        jLabel4.setText("Score :");
        getContentPane().add(jLabel4);
        jLabel4.setBounds(20, 170, 40, 14);
        getContentPane().add(Name);
        Name.setBounds(100, 130, 90, 20);
        getContentPane().add(JScore);
        JScore.setBounds(60, 170, 120, 0);
        getContentPane().add(Jscore);
        Jscore.setBounds(100, 160, 100, 20);

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/Score-logo-transparent.png"))); // NOI18N
        getContentPane().add(jLabel1);
        jLabel1.setBounds(0, 0, 368, 222);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(YourScore.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(YourScore.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(YourScore.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(YourScore.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new YourScore().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel JScore;
    private javax.swing.JLabel Jscore;
    private javax.swing.JLabel Name;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    // End of variables declaration//GEN-END:variables
}
